import { Component, OnInit } from '@angular/core';
import { FetchService } from "../../../../core/net/fetch.service";
import * as _ from 'lodash';
import { format, subDays } from 'date-fns';

import { DomSanitizer, SafeResourceUrl } from "@angular/platform-browser";
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
  selector: 'app-wt-monthly-active',
  templateUrl: './wt-monthly.component.html',
  styleUrls: ['./wt-monthly.component.scss']
})
export class WtMonthlyActiveComponent implements OnInit {
  yearValue = 2020;
  monthPickerValue = new Date().getMonth();
  areaType = 2;
  serverUrl = (window as any).environment.reportUrlActive;
  iframeSrc: SafeResourceUrl;
  range = ["", new Date()];

  selectedValue = "17";
  orderTypeText = "正序";
  orderType = true;
  frId = "17";
  sort = "1";
  irrigationType = 1;




  constructor(
    private fetchService: FetchService,
    private sanitizer: DomSanitizer,
    private message: NzMessageService

  ) {
  }

  ngOnInit() {
    if (parseFloat(format(this.range[1], 'MM')) > 9) {
      this.range = ["2021-10-1", new Date()];
    } else {
      this.range = ["2021-1-1", new Date()];
    }
    this.queryInfo();
  }

  queryInfo() {

    const beginTime = format(this.range[0], 'YYYY-MM-DD');
    const endTime = format(this.range[1], 'YYYY-MM-DD');
    console.log(format(this.range[1], 'YYYY'));
    const year = this.yearValue;
    const month = this.monthPickerValue + 1;
    const reportName = '';
    // this.irrigationType === 1 ? reportName = "灌溉进度报表1" : reportName = "灌溉进度报表2";
    const token = localStorage.token;
    let link = "";
    link = `http://172.30.134.242:9008/api/ureport/preview?_u=wrs:灌溉用水量.ureport.xml&_t=0&edDate=${endTime}&fId=${this.frId}&orderBy=${this.sort}&stDate=${beginTime}`;
    this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(link);
  }

  dateChangeActive(val) {

    this.queryInfo();




  }
  // 选择管理处
  onchangeGlc(val) {
    this.frId = val;
    this.queryInfo();

  }
  dateChange(val) {
    this.areaType = val;
    this.queryInfo();
  }
  // 改变升降序
  changeOrderType() {
    this.orderType = !this.orderType;
    this.orderType ? this.orderTypeText = "正序" : this.orderTypeText = "倒序";
    this.orderType ? this.sort = "1" : this.sort = "2";
    this.queryInfo();
  }
  irrigationChange(val) {
    this.irrigationType = val;

    this.queryInfo();
  }
}

